import 'package:flutter/material.dart';
import 'package:provide/provide.dart';
import '../provide/setting.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter/cupertino.dart';

class SettingPage extends StatefulWidget {
  final Widget child;

  SettingPage({Key key, this.child}) : super(key: key);

  _SettingPageState createState() => _SettingPageState();
}

class _SettingPageState extends State<SettingPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('设置'),),
      body: Provide<SettingProvide>(
        builder: (context,child,val){
          return SingleChildScrollView(
            child: Column(
              children: <Widget>[
                _themeColor(val.colorList),
                _noImage()
              ],
            ),
          );
        },
      ),
    );
  }

  // 主体颜色设置
  Widget _themeColor(list){
    List colorList = list;
    return 
    ExpansionTile(
      // backgroundColor: Colors.redAccent,
      leading: Icon(Icons.accessibility),
      title: Text('主题颜色'),
      children: <Widget>[
        Wrap(
          spacing: 5,
          runSpacing: 5,
          children: colorList.map((color){
            return InkWell(
              onTap: (){
                Provide.value<SettingProvide>(context).changeTheme(color);
              },
              child: Container(
                margin: EdgeInsets.only(bottom: 5),
                width: ScreenUtil().setWidth(60),
                height: ScreenUtil().setWidth(60),
                color: color,
              ),
            );
          }).toList(),
        )
      ],
    );
  }

  // 无图模式
  Widget _noImage(){
    return ListTile(
      leading: Icon(Icons.broken_image),
      title: Text('无图模式'),
      trailing: Provide<SettingProvide>(
        builder: (context,child,val){
          return CupertinoSwitch(
            value: val.noImage,
            onChanged: (bool value){
              Provide.value<SettingProvide>(context).wantImage(value);
            },
          );
        },
      )
    );
  }
}